package edu.ccut.titan.component.impl.directory;

import java.util.Enumeration;

import org.osgi.framework.Bundle;

import edu.ccut.titan.component.ComponentFactory;
import edu.ccut.titan.component.IBundleInfo;
import edu.ccut.titan.component.TitanComponentException;

public class TitanActionDirectoryInfo extends AbstractDirectoryInfo {
	
	private static final String TITAN_ACTION_COMPONENT_FILE_POSTFIX = ".action.xml";

	public TitanActionDirectoryInfo() {
		super(TITAN_DIRECTORY_TYPE_ACTION);
	}

	@SuppressWarnings("unchecked")
	public void load(Bundle bundle, IBundleInfo bundleInfo)
			throws TitanComponentException {
		
		Enumeration<String> actionFiles = bundle.getEntryPaths(super
				.getDirectoryPath());

		while (actionFiles.hasMoreElements()) {
			String actionFile = actionFiles.nextElement();

			if (actionFile != null
					&& actionFile.endsWith(TITAN_ACTION_COMPONENT_FILE_POSTFIX)) {
				bundleInfo.addComponentInfo(ComponentFactory
						.getActionComponentInfo(bundle, actionFile));

			}
		}
	}
}
